import { chekUsername, chekPassword } from "@/utils/check"
import './index.css'
import './index.less'
import imgLogo from './assets/logo.png'
import axios from "axios"
//查找标签 把图片资源设置给src
document.querySelector('.logo-img').src = imgLogo

const button = document.querySelector('button')

button.addEventListener('click', function (e) {
    //获取元素
    const usernameVal = document.querySelector('.username').value
    const passwordVal = document.querySelector('.password').value
    // console.log(usernameVal, passwordVal)

    //判断长度
    if (chekUsername(usernameVal) === false) {
        alert('用户名不合法，长度必须超过6位')
        return
    }
    if (chekPassword(passwordVal) === false) {
        alert('密码不合法，长度必须超过8位')
        return
    }

    //3.发送请求
    axios.post('https://hmajax.itheima.net/api/register', {
        username: usernameVal,
        password: passwordVal,
    }).then((res) => {
        //处理成功
        console.log(res.data.data.id)
        alert(`注册成功,用户名id为${res.data.data.id}`)
    }).catch((err) => {
        //处理失败
        console.log(err)
        alert(`注册失败，${err.response.data.message}`)
    })
})

const username = 'itheima'
console.log(username)
console.log(`用户名为${username}`)
const arr = [1, 2, 3, 4, 5]
const res = arr.map((item) => item * 2)
console.log(res123)